package web;

import enity.User;
import service.Servlet;
import service.impl.Servletimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "MyServlet")
public class MyServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String username = request.getParameter("username");
        String pwd = request.getParameter("pwd");

        Servlet user=new Servletimpl();

        User user1 = new User();
        user1.setUsername(username);
        user1.setPwd(pwd);
        User user2 = user.login(user1);
        if(user2!=null){
            request.getSession().setAttribute("user2",user2);
            request.getRequestDispatcher("ha.jsp").forward(request,response);
            //            //response.sendRedirect("index.jsp");

        }else{
            //request.getRequestDispatcher("ha.jsp").forward(request,response);
          response.sendRedirect("index.jsp");
            System.out.println("c");
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
